<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@include file="../../common/mastertopedit.jsp"%>
<script type="text/javascript" src="${ctx}/js/region.js"></script>
<input type="hidden" id="stockId" value="${model.stockId}">
<div class="form-horizontal pt-15  form-clean-magin">
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">仓库编码</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="stockCode" id="stockCode" maxlength="100" type="text"  pattern="/[^a-zA-Z\d]+/"
				<c:if test="${model.scmStockInfo.id!=null}">disabled="disabled"</c:if>
				value="${model.scmStockInfo.stockCode}"> <i
				class="plum-sign-right">*</i>
		</div>
	</div>

	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">仓库名称</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="stockName" id="stockName" maxlength="100" type="text"
				value="${model.scmStockInfo.stockName}"> <i
				class="plum-sign-right">*</i>
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">仓库性质</label>
		<div class="col-xs-9">
			<label class="radio-inline"> <input name="stockType"
				type="radio"
				<c:if test="${model.scmStockInfo.stockType==1}">checked="checked"</c:if>
				value="1"> 工厂仓
			</label> 
			<label class="radio-inline"> 
				<input name="stockType"  type="radio" 
				<c:if test="${model.scmStockInfo.stockType==2}">checked="checked"</c:if> value="2">中转仓
			</label>
			<label class="radio-inline"> 
				<input name="stockType"  type="radio" 
				<c:if test="${model.scmStockInfo.stockType==3}">checked="checked"</c:if> value="3">外包仓
			</label>
			<label class="radio-inline"> 
				<input name="stockType"  type="radio" 
				<c:if test="${model.scmStockInfo.stockType==4}">checked="checked"</c:if> value="4">自建仓
			</label>
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">计入库存</label>
		<div class="col-xs-9">
			<label class="radio-inline"> <input name="isInventory"
				type="radio"
				<c:if test="${model.scmStockInfo.isInventory==1}">checked="checked"</c:if>
				value="1"> 是
			</label> 
			<label class="radio-inline"> 
				<input name="isInventory"  type="radio" 
				<c:if test="${model.scmStockInfo.isInventory==0}">checked="checked"</c:if> value="0">否
			</label>
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">关联供应商</label>
		<div class="col-xs-9">
			<select id="factoryId" class="form-control form-control-260 pull-left">
				<option value=""
					<c:if test="${model.scmStockInfo.factoryId==null}">selected="selected"</c:if>>请选择</option>
				<c:forEach items="${model.factorys}" var="lo" varStatus="itemStatus">
					<option value="${lo.id}"
						<c:if test="${model.scmStockInfo.factoryId==lo.id}">selected="selected"</c:if>>${lo.factoryName}</option>
				</c:forEach>
			</select>
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">联系人</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="stockContacts" id="stockContacts" maxlength="11" type="text"
				value="${model.scmStockInfo.stockContacts}"   > 
		</div>
	</div>
	
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">手机号码</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="mobile" id="mobile" maxlength="20" type="text"
				value="${model.scmStockInfo.mobile}"  pattern="/[^\d]+/" > 
		</div>
	</div>
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">座机</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="tel" id="tel" maxlength="20" type="text"
				value="${model.scmStockInfo.tel}"> 
		</div>
	</div>
	
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">地址</label>
		<div class="col-xs-9">
			<input type="hidden" id="pid" value="${model.scmStockInfo.provinceId}">
			<input type="hidden" id="cid" value="${model.scmStockInfo.cityId}">
			<input type="hidden" id="aid" value="${model.scmStockInfo.areaId}">
			<select id="provinceId" class="form-control form-control-125 pull-left"   onchange="selectProvince()" >
				<option value="" >选择市</option>
			</select>
			<select id="cityId" class="form-control form-control-125 pull-left" onchange="selectCity()" >
				<option value="" >选择市</option>
			</select>
			<select id="areaId" class="form-control form-control-125 pull-left"  >
				<option value="" >选择市</option>
			</select>
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">详细地址</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="address" id="address" maxlength="100" type="text"
				value="${model.scmStockInfo.address}"> 
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">备注</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="remark" id="remark" maxlength="100" type="text"
				value="${model.scmStockInfo.remark}"> 
		</div>
	</div>
</div>

<div class="form-group text-center">
	<button type="button" class="runmi-btn runmi-primary"
		onclick="backIndex()">取消</button>
	<button type="button" class="runmi-btn runmi-sure-btn" onclick="save()">保存</button>
</div>
<script type="text/javascript">
  function save(){	  
  		var stockId=$('#stockId').val();	
		var postData="stockId=" +stockId ;
		
		var stockCode=$('#stockCode').val();
		if(stockCode=='' && stockId==''){
			layer.alert('请输入仓库编码');
	    	return;
		}
		postData=postData + "&stockCode=" + encodeURIComponent(stockCode);
		
		var stockName=$('#stockName').val();
		if(stockName==''){
			layer.alert('请输入仓库名称');
	    	return;
		}
		postData=postData + "&stockName=" + encodeURIComponent(stockName);
		
		var stockType= $("input[name='stockType']:checked").val();
		if(stockType==undefined){
			layer.alert('请选择仓库性质');
	    	return;
		}
		postData=postData + "&stockType=" + stockType;
		
		var isInventory= $("input[name='isInventory']:checked").val();
		if(isInventory==undefined){
			layer.alert('请选择是否计入库存');
	    	return;
		}
		postData=postData + "&isInventory=" + isInventory;
		
		var factoryId=$('#factoryId').val();
		postData=postData + "&factoryId=" + encodeURIComponent(factoryId);
		
		var stockContacts=$('#stockContacts').val();
		postData=postData + "&stockContacts=" + encodeURIComponent(stockContacts);
		
		var mobile=$('#mobile').val();
		postData=postData + "&mobile=" + encodeURIComponent(mobile);
			
		var tel=$('#tel').val();
		postData=postData + "&tel=" + encodeURIComponent(tel);
		
	
	
		var provinceId=$('#provinceId').val();
		postData=postData + "&provinceId=" + encodeURIComponent(provinceId);
		
		var cityId=$('#cityId').val();
		postData=postData + "&cityId=" + encodeURIComponent(cityId);
		
		var areaId=$('#areaId').val();
		postData=postData + "&areaId=" + encodeURIComponent(areaId);
		
		var address=$('#address').val();
		postData=postData + "&address=" + encodeURIComponent(address);
		
		var remark=$('#remark').val();
		postData=postData + "&remark=" + encodeURIComponent(remark);
		
		var url="updateStockInfo";
		if(stockId==''){
			url="saveStockInfo";
		}
		
	    layer.load(1, {shade: [0.5,'#fff']});
	    //alert(url + postData);
	    $.ajax({
	        type: "POST",
	        url: url,
	        data: postData,
	        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	        async: true, // 同步  true 异步。默认是异步
	        dataType: 'json',
	        error: function(resultdata) {
	        	layer.closeAll();
	        },
	        success: function(resultdata) {
	        	layer.closeAll();
	            if(resultdata.returnCode=="0000"){               	
	            	layer.alert('操作成功',{icon: 1}, function(){
	            	 	 parent.editReturn();
	            	});
	            }else{
	            	layer.alert(resultdata.returnMessage);
	            }
	        }
	    });
	}
  function backIndex(){	  
 	 parent.editReturn();
  }
	</script>
<%@include file="../../common/masterbottom.jsp"%>
